<template>
  <div class="chart" ref="ChartRef"/>
</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue'
import * as echarts from 'echarts'
import { lineChartOptions, pieChartOptions } from '@/utils/eChartsUtil'
import { IPieChartData } from '@/types'

const ChartRef = ref<HTMLElement>()

let chart: echarts.ECharts

onMounted(() => {
  chart = echarts.init(ChartRef.value as HTMLElement)
  const xAxisData = ['2024-01-01', '2024-01-02', '2024-01-03', '2024-01-04']
  const yAxisData = [123, 3423, 21332, 676]
  chart.setOption(lineChartOptions('日期', xAxisData, '数量', yAxisData))

  const pieData = [{
    name: '测试',
    value: 10
  }, {
    name: '测试2',
    value: 20
  }] as IPieChartData[]
  // chart.setOption(pieChartOptions('测试', '个', pieData))
})
</script>

<style lang="scss">
.chart {
  height: 400px;
  width: 640px;

  border: 2px solid #41CADB;
}
</style>
